<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta name="App-Config" content="fullscreen=yes,useHistoryState=yes,transition=yes" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="yes" name="apple-touch-fullscreen" />
		<meta content="telephone=no,email=no" name="format-detection" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title></title>
	</head>
	<link href="../c/new_renwu.css" rel="stylesheet" type="text/css" />
	<style>
		.file {
			width: 50%;
			margin: 0.5rem 0;
			height: 3rem;
			display: block;
			margin-left: 25%;
			float: left;
		}

		.file input {
			width: 100%;
			height: 100%;
			opacity: 0;
		}

		.file img {
			width: 100%;
			height: 100%;
			position: relative;
			top: 0;
			right: 0;
			opacity: 0.8;
			bottom: 0;
			left: 0;
		}

		.details {
			display: block;
			width: 90%;
			margin-left: 5%;
			color: #fff;
			font-size: 0.6rem;
		}
	</style>
	<body>
		<p style=" display: none;   width: 90%;margin-left: 5%;color: red;margin-top: 0.5rem;font-size: 0.85rem;text-align: justify;">提示:达人每日需要完成3个任务，工会每日完成两个任务，机构每日完成一个任务</p>
		<div class="main">
		</div>
	</body>
</html>
<script src="../j/api.js"></script>
<script src="../j/jquery-3.3.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/clipboard.js/1.5.12/clipboard.min.js"></script>
<script>
	//打开抖音
	function copy(tet) {
		// //text为需要复制的文本
		var text = $(tet).siblings("span").eq(0).attr("name");
		var downloader,
			scheme = text, // 需要打开的 scheme 地址
			download = 'index'; // 如果打开scheme失效的app下载地址
		// 给 id 为 open 的按钮添加点击事件处理函数
		window.location.href = scheme; // 尝试打开 scheme
		downloader = setTimeout(function() {
			api.openWin({
				name: "new_my",
				url: 'new_my.html',
				animation: {
					type: "none",
				},
				bounces: false,
				slidBackEnabled: false,
			})
		}, 3000);
	}
	// 修改头像
	function _touxiang(datu) {
		api.actionSheet({
			title: datu ? '修改大图' : '任务图片',
			cancelTitle: '取消',
			buttons: ['拍一张', '相册相册']
		}, function(ret, err) {
			var index = ret.buttonIndex;
			if (index != 3) {
				var sourceType = index == 1 ? 'camera' : 'album'
				api.getPicture({
					sourceType: sourceType,
					encodingType: 'jpg',
					mediaValue: 'pic',
					destinationType: 'url',
					allowEdit: false,
					quality: 100,
				}, function(ret, err) {
					if (ret) {
						if (ret.data) {
							_url({
								img: ret.data,
								animation: true,
								datu: datu
							}, 'renwu_adds');
						}
					}
				});
			}
		});
	}

	apiready = function() {
		var agent;
		_ajax('member/info', function(ret, err) {
			if (ret.agent == 0 && ret.levels == 0) {
				agent = 0;
			} else if (ret.agent == 1 && ret.levels == 0) {
				agent = 1;
			} else if (ret.agent == 1 && ret.levels == 1) {
				agent = 2;
			} else if (ret.agent == 1 && ret.levels == 2) {
				agent = 3;
			}
		})
		_ajax1('task/index', function(ret, err) {
			console.log(JSON.stringify(ret));
			if (ret != "") {
				if (ret.ret && ret.ret.length > 0) {
					var tpl = '';
					for (var i = 0; i < ret.ret.length; i++) {
						tpl += '<div class="main_a">';
						tpl += '<p class="titp" name="a" ids="' + ret.ret[i].id +
							'"style="height:3rem"><span style="font-size:1rem">' + ret.ret[i].title +
							'</span><span></span><span></span></p>';
						tpl += '</div >';
					}
					$(".main").html(tpl);
				}
			}
		})
		$(".main").on("click", ".sx-img", function() {
			var id = $(this).attr("ids");
			var jinbi = $(this).attr("jinbi");
			localStorage.setItem("id", id);
			localStorage.setItem("jinbi", jinbi);
			_touxiang();
		})
		$(".main").on("click", ".titp", function() {
			var nm = $(this).attr("name");
			var ind = $(this).parents(".main_a").index();
			$(".renwu_list").hide();
			$(".titp").attr("name", "a");
			$(".titp").children("span").eq(1).css("background-position-y", "0px");
			if (nm == "a") {
				$(this).siblings(".renwu_list").show();
				$(this).children("span").eq(1).css("background-position-y", "-13px")
				$(this).attr("name", "b");
				var id = $(this).attr("ids");
				var len = $(".main_a").eq(ind).children(".renwu_list").length;
				if (len > 0) {} else {
					_ajax1('task/subtasks', function(rets, err) {
						console.log(JSON.stringify(rets));
						if (rets.ret) {
							if (rets.ret != "" && rets.ret.length > 0 && rets.ret) {
								var tpl = '';
								tpl += '<div class="renwu_list">';
								for (var m = 0; m < rets.ret.length; m++) {
									if (agent == 1 || agent == "1") {
										if (rets.ret[m].daren == 1 || rets.ret[m].daren == "1") {
											tpl += '<p class="renwen_p" id="' + rets.ret[m].id + '">';
											tpl += '<img src="http://qiniu.live.kxg99.com/' + rets.ret[m].first_img +
												'"style="width:25%;float:left;">';
											tpl += '<span name="' + rets.ret[m].title +
												'"style="width:60%;display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;">' +
												rets.ret[m].msg + '</span>';
											tpl +=
												'<smap style="width:96%;padding-bottom: 0.5rem;margin-top: 0.5rem;float:left;"><span style="width:50%;margin-left:0;">任务剩余量';
											var ln = (rets.ret[m].total_num - rets.ret[m].current_num) / rets.ret[m].total_num*100;
											var num = (parseInt(rets.ret[m].total_num - rets.ret[m].current_num) / parseInt(rets.ret[m].total_num)) *
												100
											tpl += '' + ln.toFixed(2) +
												'%</smap><span style="width: 45%;display: block; height: 0.3rem;margin-top:-1.5rem; background:#6d6b6b;float: right;"><small style="float: left;background:#e14b00;width:' +
												ln.toFixed(2) + '%"></small></span></span></p>';
										} else {}

									} else if (agent == 2 || agent == "2") {

										tpl += '<p class="renwen_p" id="' + rets.ret[m].id + '">';
										tpl += '<img src="http://qiniu.live.kxg99.com/' + rets.ret[m].first_img +
											'"style="width:25%;float:left;">';
										tpl += '<span name="' + rets.ret[m].title +
											'"style="width:60%; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; ">' +
											rets.ret[m].msg + '</span>';
										tpl +=
											'<smap style="width:96%;padding-bottom: 0.5rem;margin-top: 0.5rem;float:left;"><span style="width:50%;margin-left:0;">任务剩余量';
										var ln = (rets.ret[m].total_num - rets.ret[m].current_num) / rets.ret[m].total_num*100;
										var num = (parseInt(rets.ret[m].total_num - rets.ret[m].current_num) / parseInt(rets.ret[m].total_num)) *
											100
										tpl += '' + ln.toFixed(2) +
											'%</smap><span style="width: 45%;display: block; height: 0.3rem;margin-top:-1.5rem; background:#6d6b6b;float: right;"><small style="float: left;background:#e14b00;width:' +
											ln.toFixed(2) + '%"></small></span></span></p>';


									} else if (agent == 3 || agent == "3") {
										tpl += '<p class="renwen_p" id="' + rets.ret[m].id + '">';
										tpl += '<img src="http://qiniu.live.kxg99.com/' + rets.ret[m].first_img +
											'"style="width:25%;float:left;">';
										tpl += '<span name="' + rets.ret[m].title +
											'"style="width:60%;display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;">' +
											rets.ret[m].msg + '</span>';
										tpl +=
											'<smap style="width:96%;padding-bottom: 0.5rem;margin-top: 0.5rem;float:left;"><span style="width:50%;margin-left:0;">任务剩余量';
										var ln = (rets.ret[m].total_num - rets.ret[m].current_num) / rets.ret[m].total_num*100;
										var num = (parseInt(rets.ret[m].total_num - rets.ret[m].current_num) / parseInt(rets.ret[m].total_num)) *
											100
										tpl += '' + ln.toFixed(2) +
											'%</smap><span style="width: 45%;display: block; height: 0.3rem;margin-top:-1.5rem; background:#6d6b6b;float: right;"><small style="float: left;background:#e14b00;width:' +
											ln.toFixed(2)+ '%"></small></span></span></p>';
									} else {
										if (agent != 1 && agent != 2 && agent != 3) {
											var hl = $(".main_a").eq(ind).html();
											str = hl + "<p style='color:#fff;font-size:0.85rem;text-align: center;'>暂无任务</p>";
											$(".main_a").eq(ind).html(str);
											$(".main_a").eq(ind).children(".titp").css("pointer-events", "none");
										} else {
											var hl = $(".main_a").eq(ind).html();
											str = hl + "<p style='color:#fff;font-size:0.85rem;text-align: center;'>暂无任务</p>";
											$(".main_a").eq(ind).html(str);
											$(".main_a").eq(ind).children(".titp").css("pointer-events", "none");

										}

									}
								}
								tpl += '</p>';
								tpl += '</div>';
								// console.log(tpl);
								var hl = $(".main_a").eq(ind).html();
								str = hl + tpl;
								$(".main_a").eq(ind).html(str);
							} else {

								var hl = $(".main_a").eq(ind).html();
								str = hl + "<p style='color:#fff;font-size:0.85rem;text-align: center;'>暂无任务</p>";
								$(".main_a").eq(ind).html(str);
								$(".main_a").eq(ind).children(".titp").css("pointer-events", "none");
							}
						} else {

						}
					}, {
						type: id
					})
				}
			} else {
				$(this).siblings(".renwu_list").hide();
				$(this).children("span").eq(1).css("background-position-y", "0px")
				$(this).attr("name", "a");
			}
		})

		$(".main").on("click", ".renwen_p", function() {
			var id = $(this).attr("id");
			// alert(id);
			localStorage.setItem("rwu", id);
			_url({
				url: 'new_renwudetails',
				title: '任务详情'
			});

		})
	}
</script>
